from pathlib import Path
import sys

# 项目根目录
RELATIVE_PATH = Path(__file__).parent.parent.parent.parent
PACKED_PATH = Path(getattr(sys, '_MEIPASS', '')).parent / 'app'
# 默认优先用打包路径
PROJECT_PATH = PACKED_PATH if PACKED_PATH.exists() else RELATIVE_PATH

DEFAULT_PATH = {
    "_LOG_PATH/" : PROJECT_PATH / "logs",
    "_CONFIG_PATH/" : PROJECT_PATH / "configs",
    "_MODELS_PATH/" : PROJECT_PATH / "models",
    "_INPUT_PATH/" : PROJECT_PATH / "inputs",
    "_OUTPUT_PATH/" : PROJECT_PATH / "assets",
}

def solve_path(original_path):
    if isinstance(original_path, str):
        # 应用映射规则
        for placeholder, mapped_path in DEFAULT_PATH.items():
            if original_path.startswith(placeholder):
                relative = original_path.replace(placeholder, '', 1)
                return str(mapped_path / relative)

    return original_path